Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] change utils.logger.warning -> utils.warn #9434

Merged
merged 5 commits into from
Jun 2, 2021

Conversation

sappelhoff
Copy link
Member

closes #9432

A simple PR to improve consistency in the code base: using mne.utils.warn, instead of different warning calls.

@sappelhoff
Copy link
Member Author

CIs were failing when I pushed the changes for the fixes.py file due to a circular import: 8ececbe

in particular, this function was the problem:

mne-python/mne/fixes.py

Lines 29 to 41 in f42f612

def _median_complex(data, axis):
"""Compute marginal median on complex data safely.
Can be removed when numpy introduces a fix.
See: https://github.com/scipy/scipy/pull/12676/.
"""
# np.median must be passed real arrays for the desired result
if np.iscomplexobj(data):
data = (np.median(np.real(data), axis=axis)
+ 1j * np.median(np.imag(data), axis=axis))
else:
data = np.median(data, axis=axis)
return data

and it looks like the scipy PR for this temporary fix was merged: scipy/scipy#12676. So perhaps it could be removed now (not sure, because the numpy issue related to that is still open: numpy/numpy#12943)

@larsoner
Copy link
Member

larsoner commented May 30, 2021

We try to keep code in fixes as close to copy-paste as possible to the upstream code, so I wouldn't change anything in there.

Even if an upstream fix has been merged we support several versions back so there's a ~2 year delay before we can remove things from fixes

@@ -149,7 +149,7 @@ def run_subprocess(command, return_code=False, verbose=None, *args, **kwargs):
break
else:
err = err.decode('utf-8')
logger.warning(err)
warn(err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to confuse the tests. I don't really see how, because the traceback is not very informative: https://github.com/mne-tools/mne-python/pull/9434/checks?check_run_id=2704866135

Except for three failures where coverage.py warns about something, it always looks like this:

 <decorator-gen-2>:24: in run_subprocess
    ???
mne/utils/misc.py:152: in run_subprocess
    warn(err)
mne/utils/_logging.py:358: in warn
    warnings.warn_explicit(
E   RuntimeWarning:

Do you have an idea what's going on @larsoner?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warnings are treated as errors in tests. Now you are emitting a warning, rather than logging with a WARNING level of verbosity, hence it raises an error. The easiest thing is probably to add an ignore line to mne/conftest.py for this "include is ignored because"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... actually in this case I think logger.warn is arguably the correct behavior since this is basically an advanced wrapper for subprocess. I think we should restore the logger.warning for this one to mirror the logger.info that is used for stdout-level messages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, that makes sense. Also thanks for directly pushing those commits. It all passes now.

@sappelhoff sappelhoff changed the title change utils.logger.warning -> utils.warn [MRG] change utils.logger.warning -> utils.warn Jun 1, 2021
@agramfort agramfort merged commit e6a0298 into mne-tools:main Jun 2, 2021
@sappelhoff sappelhoff deleted the fix/warn/consistency branch June 2, 2021 10:52
larsoner added a commit to larsoner/mne-python that referenced this pull request Jun 2, 2021
* upstream/main:
  [MRG] change utils.logger.warning -> utils.warn (mne-tools#9434)
  FIX : rank computation from info now uses SSS proc history if only grad or mag are present (mne-tools#9435)
  MRG: Enable interpolation for all fNIRS types (mne-tools#9431)
  FIX: brain save_movie (mne-tools#9426)
  ENH: Add mne.export (mne-tools#9427)
  ENH: Test more on pre [skip circle] (mne-tools#9423)
  MRG, ENH: Speed up brain test (mne-tools#9422)
  MAINT: Update URL [ci skip]
  MNT: Reduce number of calls to _update (mne-tools#9407)
  MRG: Tutorial improvements (mne-tools#9416)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of "warn", "warnings.warn", "logger.warning" in the codebase
3 participants